<template>
    <addEditBaseWorkRecordView ref="addEditBaseWorkRecordView" />
    <addFileView ref="addFileView" />
    <el-dialog v-model="dialogVisible" title="详情" width="50%" :before-close="handleClose">
        <!-- <span>This is a message</span> -->
        <div class="line">
            <p class="pName">人员姓名：</p>
            <div>{{ this.recordData.teacherName }}</div>
        </div>
        <div class="line">
            <p class="pName">部门名称：</p>
            <div>{{ this.recordData.departmentName }}</div>
        </div>
        <div class="line">
            <p class="pName">工作记录：</p>
            <div>{{ this.recordData.detail }}</div>
        </div>
        <div class="line">
            <p class="pName">工作时长：</p>
            <div>{{ this.recordData.hours }}</div>
        </div>
        <div class="line">
            <p class="pName">创建时间：</p>
            <div>{{ this.recordData.createTime }}</div>
        </div>
        <div class="line">
            <p class="pName">工作照片：</p>
            <div class="demo-image__preview" >
                <!-- <img :src="item" > -->
                <el-image style="width: 100px; height: 100px" :src="item" :zoom-rate="1.2" :max-scale="7"
                    :min-scale="0.2" :preview-src-list="this.recordData.images" :initial-index="index + 1" fit="cover"
                    v-for="(item, index) in this.recordData.images" :key="index"  />
            </div>
        </div>
        <template #footer>
            <span class="dialog-footer">
                <!-- <el-button @click="dialogVisible = false">Cancel</el-button> -->
                <el-button type="primary" @click="dialogVisible = false">
                    确认
                </el-button>
            </span>
        </template>
    </el-dialog>
    <el-main>
        <div class="teacher">
            <div class="app-table">
                <div class="app-body">
                    <el-form :inline="true" class="demo-form-inline" v-model="form">
                        <!-- <el-form-item label="工作记录">
                            <el-input placeholder="请输入工作记录" v-model="form.detail"></el-input>
                        </el-form-item> -->
                        <!-- <el-form-item label="上报日期">
                            <el-input placeholder="请输入上报日期" v-model="form.day"></el-input>
                        </el-form-item> -->
                        <!-- <el-form-item label="工作图片">
                            <el-input placeholder="请输入工作图片" v-model="form.images"></el-input>
                        </el-form-item> -->
                        <!-- <el-form-item label="修改人员工号">
                            <el-input placeholder="请输入修改人员工号" v-model="form.updateTeacherNumber"></el-input>
                        </el-form-item>
                        <el-form-item label="修改人员">
                            <el-input placeholder="请输入修改人员" v-model="form.updateTeacher"></el-input>
                        </el-form-item> -->
                        <el-form-item label="部门名称">
                            <el-input placeholder="请输入部门名称" v-model="form.departmentName"></el-input>
                        </el-form-item>
                        <el-form-item label="人员工号">
                            <el-input placeholder="请输入人员工号" v-model="form.teacherNumber"></el-input>
                        </el-form-item>
                        <el-form-item label="人员姓名">
                            <el-input placeholder="请输入人员姓名" v-model="form.teacherName"></el-input>
                        </el-form-item>
                        <el-form-item>
                            <el-button class="serach_btn" type="primary" @click="onSubmit"
                                @keyup.enter="searchEnter">搜索</el-button>
                            <!-- <el-button class="add_btn" type="success" @click="add">添加</el-button> -->
                            <el-button class="add_btn" type="warning" @click="exportExcel">导出报表</el-button>
                            <!-- <el-button type="danger" @click="importExcel">批量导入<el-icon class="el-icon--right">
                                    <Upload />
                                </el-icon></el-button> -->
                        </el-form-item>
                    </el-form>
                    <el-table :data="list" style="width: 100%" :row-class-name="tableRowClassName">
                        <el-table-column type="index" width="80" label="序号" />
                        <el-table-column prop="detail" label="工作记录" show-overflow-tooltip />
                        <el-table-column prop="hours" label="工作时长" width="100" />
                        <el-table-column prop="departmentName" label="部门名称" width="200" />
                        <!-- <el-table-column prop="images" label="工作图片">
                            <template style="display: block" #default="scope">
                                <el-image style="width: 100px; height: 100px" :src="item"
                                    v-for="(item, index) in scope.row.images" :key="index" />
                            </template>
                        </el-table-column> -->
                        <el-table-column prop="teacherName" label="人员姓名" width="150" />
                        <el-table-column prop="createTime" label="创建时间" />
                        <!-- <el-table-column prop="updateTeacher" label="修改人员" /> -->
                        <!-- <el-table-column prop="id" label="id" /> -->
                        <!-- <el-table-column prop="departmentId" label="部门id" /> -->
                        <!-- <el-table-column prop="day" label="上报日期" /> -->
                        <!-- <el-table-column prop="teacherNumber" label="提交人工号" /> -->
                        <!-- <el-table-column prop="updateTeacherNumber" label="修改人员工号" /> -->
                        <!-- <el-table-column prop="updateTime" label="修改时间" /> -->
                        <el-table-column label="操作" width="140px">
                            <template style="display: block" #default="scope">
                                <el-button class="edit_btn" size="small" type="success"
                                    @click="goDetail(scope.row.id)">详情
                                </el-button>
                                <!-- <el-button class="edit_btn" size="small" type="success"
                                    @click="editBaseWorkRecord(scope.row)">编辑
                                </el-button> -->
                                <el-button class="del_btn" size="small" type="danger"
                                    @click="deleteBaseWorkRecord(scope.row.id)">删除
                                </el-button>
                            </template>
                        </el-table-column>
                        <template v-slot:empty>
                            <el-empty description="暂无数据"></el-empty>
                        </template>
                    </el-table>
                    <el-config-provider :locale="locale">
                        <el-pagination :total="total" :page-size="limit" :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
                            layout="total, sizes, prev, pager, next, jumper" @size-change="changePageSize"
                            @current-change="changeCurrentPage">
                        </el-pagination>
                    </el-config-provider>
                </div>
                <bottomView />
            </div>
        </div>
    </el-main>
</template>
<script>
import addEditBaseWorkRecordView from "@/components/workRecord/addEditBaseWorkRecord.vue";
import addFileView from "@/components/addExcelFile.vue";
import { ElConfigProvider, ElMessageBox, ElMessage } from "element-plus";
import zhCn from "element-plus/lib/locale/lang/zh-cn";
import { httpService } from "@/utils/httpService";
import { Picture as IconPicture, Upload } from "@element-plus/icons-vue";
import bottomView from "@/components/bottom.vue";

export default {
    name: "BaseWorkRecordListView",
    data() {
        return {
            type: 0,
            title: "",
            page: 0,
            pageSize: 10,
            total: 0,
            limit: 10,
            list: [],
            form: {
                detail: "",
                departmentName: "",
                day: "",
                images: "",
                teacherNumber: "",
                teacherName: "",
                updateTeacherNumber: "",
                updateTeacher: "",
            },
            dialogVisible: false,
            recordData: {},
        };
    },
    components: {
        addEditBaseWorkRecordView,
        addFileView,
        IconPicture,
        ElConfigProvider,
        ElMessageBox,
        ElMessage, Upload, bottomView
    },
    setup() {
        return {
            locale: zhCn,
        };
    },
    mounted() {
        this.getBaseWorkRecordList();
    },
    watch: {
        $route() {
            this.getBaseWorkRecordList();
        },
    },
    methods: {
        handleError(num) {
            console.log(num);
        },
        searchEnter: function (e) {
            // 使用 which 和 keyCode 属性来解决兼容问题
            var keyCode = window.event ? e.keyCode : e.which;
            var val = e.target.value;
            if (keyCode == 13 && val) {
                this.getBaseWorkRecordList();
            }
        },
        add() {
            this.$refs.addEditBaseWorkRecordView.title = "添加工作汇报表"
            this.$refs.addEditBaseWorkRecordView.personnelType = this.type
            this.$refs.addEditBaseWorkRecordView.dialogFormVisible = true;
        },
        editBaseWorkRecord(obj) {
            this.$refs.addEditBaseWorkRecordView.title = "修改信息"
            this.$refs.addEditBaseWorkRecordView.getBaseWorkRecordById(obj.id);
            this.$refs.addEditBaseWorkRecordView.dialogFormVisible = true;
        },
        deleteBaseWorkRecord(id) {
            ElMessageBox.confirm("确定要删除本条记录吗？", "提醒", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning",
            })
                .then(() => {
                    httpService("/javaApi/baseWorkRecord/deleteById", "id=" + id, "post").then(
                        (data) => {
                            if (data.code == 200) {
                                ElMessage.success("删除成功");
                                this.getBaseWorkRecordList();
                            } else {
                                ElMessage.error("删除失败，请重试！");
                            }
                        }
                    );
                })
                .catch(() => {
                });
        },
        goDetail(id) {
            httpService("/javaApi/baseWorkRecord/queryById", { id: id }, "get").then(
                (data) => {
                    // this.recordData = data;
                    // this.recordData.images = this.recordData.images.split(',')
                    // this.recordData.images = this.recordData.images.filter(item => item != '')
                    // // this.recordData.images = this.recordData.images.map(item => `http://192.168.9.22:8088/javaApi` + item)
                    // this.recordData.images = this.recordData.images.map(item => `https://wx.zhengzhong.cn` + item)
                    // // console.log(this.recordData);
                    let dataArr = data
                    if (dataArr.images != '') {
                        dataArr.images = data.images.slice(1, data.images.length).split(',')
                        dataArr.images = dataArr.images.map(item => `https://wx.zhengzhong.cn` + item + '.jpg')
                    }
                    this.recordData = dataArr;
                    console.log(this.recordData);
                }
            );
            this.dialogVisible = true
        },
        reloadData() {
            this.page = 1;
            this.getBaseWorkRecordList()
        },
        importExcel() {
            this.$refs.addFileView.dialogFormVisible = true;
            this.$refs.addFileView.title = "批量导入工作汇报表";
            this.$refs.addFileView.uploadApiUrl = "/javaApi/baseWorkRecord/importExcel";
        },
        exportExcel() {
            httpService(
                "/javaApi/baseWorkRecord/exportExcel",
                {
                    "detail": this.form.detail,
                    "departmentName": this.form.departmentName,
                    "day": this.form.day,
                    "images": this.form.images,
                    "teacherNumber": this.form.teacherNumber,
                    "teacherName": this.form.teacherName,
                    "updateTeacherNumber": this.form.updateTeacherNumber,
                    "updateTeacher": this.form.updateTeacher,
                },
                "get"
            ).then((data) => {
                if (data.code == 200) {
                    window.open('https://wx.zhengzhong.cn' + data.message, '_blank')
                }
            });
        },
        onSubmit() {
            this.getBaseWorkRecordList();
        },
        // 每页记录数改变，size：回调参数，表示当前选中的“每页条数”
        changePageSize(size) {
            this.pageSize = size;
            this.limit = size;
            this.getBaseWorkRecordList();
        },

        // 改变页码，page：回调参数，表示当前选中的“页码”
        changeCurrentPage(page) {
            this.page = page;
            this.getBaseWorkRecordList();
        },
        tableRowClassName({ row, rowIndex }) {
            return "";
        },
        getBaseWorkRecordList() {
            httpService(
                "/javaApi/baseWorkRecord/list/" + this.page + "/" + this.pageSize,
                {
                    "detail": this.form.detail,
                    "departmentName": this.form.departmentName,
                    "day": this.form.day,
                    "images": this.form.images,
                    "teacherNumber": this.form.teacherNumber,
                    "teacherName": this.form.teacherName,
                    "updateTeacherNumber": this.form.updateTeacherNumber,
                    "updateTeacher": this.form.updateTeacher,
                },
                "get"
            ).then((data) => {
                // console.log(data.list);
                this.list = data.list;
                this.total = data.total;
                this.pageCount = data.pages;
                // this.list.map(item => {
                //     item.images = item.images.split(',').map(val => {
                //         if (val == '') {
                //             return val = ''
                //         } else {
                //             return val = 'http://192.168.9.22:8088/javaApi' + val
                //             // return val = 'https://wx.zhengzhong.cn' + val
                //         }
                //     })
                // })
                this.list.map(item => {
                    return item.hours = item.hours / 10
                })
                console.log(this.list);
            });
        },
    },
};
</script>
<style scoped>
.el-main {
    padding: 0px;
}

.teacher-content {
    width: 100%;
}

.app-table {
    background: #eff3f5;
    padding: 10px;
    height: 100%;
}

.app-search {
    padding-top: 20px;
    border-top: 1px solid #dedede;
    margin-top: 20px;
}

.app-separator {
    padding-top: 10px;
    padding-bottom: 20px;
    padding-left: 10px;
}

.app-body {
    background: white;
    padding: 20px 20px 20px 20px;
    margin-bottom: 10px;
    min-height: calc(100vh - 216px);
}

.el-table .warning-row {
    --el-table-tr-bg-color: var(--el-color-warning-lighter);
}

.el-table .success-row {
    --el-table-tr-bg-color: var(--el-color-success-lighter);
}

.el-pagination {
    text-align: center;
    margin-top: 20px;
}

.serach_btn {
    background-color: #007EFF;
    color: #fff;
    border-radius: 8px;
    border: none;
}

.add_btn {
    background-color: #00c78c;
    color: #fff;
    border-radius: 8px;
    border: none;
}

.edit_btn {
    background-color: #fff;
    color: #007EFF;
    border: none;
}

.del_btn {
    background-color: #fff;
    color: #FF0000;
    border: none;
}

.line {
    display: flex;
    align-items: center;
}

.line .pName {
    width: 100px;
}

.line div {
    width: 80%;
}

.demo-image__error .image-slot {
    font-size: 30px;
}

.demo-image__error .image-slot .el-icon {
    font-size: 30px;
}

.demo-image__error .el-image {
    width: 100%;
    height: 200px;
}
</style>
